/*
 * @lc app=leetcode.cn id=206 lang=cpp
 *
 * [206] 反转链表
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        if(head == NULL)
            return head;
        
        ListNode *preHead = new ListNode(-1); //头节点
        ListNode *pre = preHead;

        while(head != NULL) 
        {
            ListNode *t = head;
            t->next = pre->next;
            pre->next = t;
            head = head->next;
        }
        return preHead->next;
    }
};
// @lc code=end

